package com.yunhe.abnormal.controller.base;

import com.yunhe.common.model.ResultObject;
import com.yunhe.common.model.data.AbnormalRuleFormulaObject;
import com.yunhe.abnormal.service.base.AbnormalRuleFormulaObjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @title: AbnormalRuleFormulaObjectController
 * @Author Chen Lun
 * @Date: 2021/1/29
 */
@Api(value = "abnormalFormulaObject",description = "异常规则公式对象维护", tags = {"Base_AbnormalFormulaObject"})
@RestController
@RequestMapping("/abnormalFormulaObject")
public class AbnormalRuleFormulaObjectController {

    @Autowired
    private AbnormalRuleFormulaObjectService abnormalRuleFormulaObjectService;

    @ApiOperation("获取全部告警规则公式对象和点号对应Map")
    @RequestMapping(value = "/findAll", method = RequestMethod.GET)
    public ResponseEntity<ResultObject> findAll() {
        Map<String, List<AbnormalRuleFormulaObject>> result = abnormalRuleFormulaObjectService.findAllFormulaObject();
        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
    }

    @ApiOperation("获取全部告警规则公式量测点号")
    @RequestMapping(value = "/measPointNumbers", method = RequestMethod.GET)
    public ResponseEntity<ResultObject> findAllMeasPointNumber()  {
        List<Long> result = abnormalRuleFormulaObjectService.findAllFormulaMeasPointNumber();
        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
    }

    @ApiOperation("清空全部告警规则公式对象和点号对应Map的缓存")
    @RequestMapping(value = "/findAll", method = RequestMethod.DELETE)
    public ResponseEntity<ResultObject> clearAllFormulaObjectRedis() {
        abnormalRuleFormulaObjectService.clearFormulaObjectRedis();
        return new ResponseEntity<>(new ResultObject<>(null), HttpStatus.OK);
    }
}
